package net.wanho.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.OutStoreDTO;
import net.wanho.mapper.OutStoreMapper;
import net.wanho.po.OutStore;
import net.wanho.service.OutStoreService;
import net.wanho.vo.OutStoreVo;
import net.wanho.vo.PageInfo;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【out_store(出库单表)】的数据库操作Service实现
* @createDate 2025-04-28 11:41:58
*/
@Service
public class OutStoreServiceImpl extends ServiceImpl<OutStoreMapper, OutStore>
    implements OutStoreService{

    @Override
    public PageInfo<OutStoreVo> outstorePageList(Integer pageNum, Integer pageSize, OutStoreDTO outStoreDTO) {
        Page<OutStoreVo> page = new Page<>(pageNum,  pageSize);
        QueryWrapper<OutStoreVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!ObjectUtil.isEmpty(outStoreDTO.getProductName()), "product_name", outStoreDTO.getProductName());
        queryWrapper.like(!ObjectUtil.isEmpty(outStoreDTO.getStoreId()), "store_id", outStoreDTO.getStoreId());
        queryWrapper.between(!ObjectUtil.isEmpty(outStoreDTO.getStartTime()), "out_time", outStoreDTO.getStartTime(), outStoreDTO.getEndTime());
        queryWrapper.eq(!ObjectUtil.isEmpty(outStoreDTO.getIsOut()), "is_out", outStoreDTO.getIsOut());
        Page<OutStoreVo> p = baseMapper.selectListByPage(page, queryWrapper);
        PageInfo<OutStoreVo> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setPageCount(page.getPages());
        pageInfo.setLimitIndex(page.offset());
        pageInfo.setResultList(p.getRecords());
        return pageInfo;


    }

    @Override
    public void outstoreConfirm(OutStore outStore) {
        outStore.setIsOut("1");
        baseMapper.updateById(outStore);
    }
}




